<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <!--计算器

        -->
        <input type="text" v-model="inputNum1" placeholder="请输入1-100之间的整数">
        <input type="text" v-model="inputNum2" placeholder="请输入1-100之间的整数">
        <button @click="com(1)">+</button>
        <button @click="com(2)">-</button>
        <button @click="com(3)">*</button>
        <button @click="com(4)">/</button>
        <h1>结果：{{result}}</h1>
    </div>
    <script>
        new Vue({
            el:'#app',
            data(){
                return{
                    inputNum1:'',
                    inputNum2:'',
                    result:''
                }
            },
            methods:{
                com(x){
                    if(isNaN(this.inputNum1) || isNaN(this.inputNum2)){
                        this.result = 'error'
                        return;
                    }
                    switch (x){
                        case 1:
                            this.result = this.inputNum1*1+this.inputNum2*1
                            break
                        case 2:
                            this.result = this.inputNum1-this.inputNum2
                            break
                        case 3:
                            this.result = this.inputNum1*this.inputNum2
                            break

                        case 4:
                            this.result = this.inputNum1/this.inputNum2
                            break

                    }
                }
            }
        })
    </script>
</body>
</html>
